package dao.concessionaria;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import dao.BaseDao;

public class LoginDao extends BaseDao {
	
	PreparedStatement comando;
	ResultSet result;
	
	public boolean buscaLogin(String login, String senha) throws SQLException{
		
		boolean bRet = false;
		
		comando = con.prepareStatement("SELECT * FROM `concessionarias` WHERE `login` = ? AND `senha` = ?");
		
		comando.setString(1, login);
		comando.setString(2, senha);
		
		result = comando.executeQuery();
		
		if(result.next())
			bRet = true;
		
		return bRet;
	}
	
	public int getId(String login, String senha) throws SQLException{
		
		comando = con.prepareStatement("SELECT * FROM `concessionarias` WHERE `login` = ? AND `senha` = ?");
		
		comando.setString(1, login);
		comando.setString(2, senha);
		
		result = comando.executeQuery();
		
		if(result.next())
			return result.getInt("id");
			
		return 0;
	}
	
}